﻿using System;
using System.Data;
using System.Collections.Generic;

using Demo.Data.Abstract;
using Demo.Model.EntityModels;

namespace Demo.Data.Concrete {
	public class PersonData: BasePersonData, IPersonData
    {
        public List<Person> GetListBySearch(Person t, int jtStartIndex , int jtPageSize , string jtSorting)
        {
            try
            {


                List<Person> lst = GetList("spPerson_GetListBySearch"
                    , CreateObjectFromReader
                    , null
                    , t.NameforSearch
                    , jtSorting
                    , jtStartIndex
                    , jtPageSize);
                return lst;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public override Person CreateObjectFromReader(IDataReader reader)
        {
            var item = base.CreateObjectFromReader(reader);

            DataTable dt = reader.GetSchemaTable();
            if (CheckExistColumn(dt, "TotalRows") && !reader.IsDBNull(reader.GetOrdinal("TotalRows"))) item.TotalRows = Convert.ToInt32(reader["TotalRows"]);

            return item;
        }

        
    }
}